define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: '/order/admin',
        detail_url: '/order/admin/detail',
        express_url: '/order/admin/express',
    };

    var orderStatus = ["待支付", "待发货", "待收货", "已完成", "已取消", "已退款"];

    return {

        index: function () {

            ea.table.render({
                init: init,
                toolbar: ['refresh'],
                cols: [[
                    {type: "checkbox"},
                    {field: 'id', width: 80, title: 'ID'},
                    {field: 'order_sn', minWidth: 80, title: '订单号', search: true},
                    {field: 'user.name', minWidth: 80, title: '下单用户'},
                    {field: 'order_amount', minWidth: 80, title: '订单金额'},
                    {
                        field: 'order_status', minWidth: 80, title: '订单状态', templet: function (data) {
                            return orderStatus[data.order_status];
                        }
                    },
                    {field: 'receive_name', minWidth: 80, title: '收货人'},
                    {field: 'receive_telephone', minWidth: 80, title: '收货电话'},
                    {field: 'receive_address', minWidth: 80, title: '详细地址'},
                    {field: 'created_at', minWidth: 120, title: '创建时间'},
                    {
                        width: 250,
                        title: '操作',
                        templet: ea.table.tool,
                        operat: [
                            [{
                                text: '详情',
                                url: init.detail_url,
                                method: 'open',
                                auth: 'order_detail',
                                class: 'layui-btn layui-btn-normal layui-btn-xs',
                            }, {
                                text: '物流',
                                url: init.express_url,
                                method: 'open',
                                auth: 'order_detail',
                                class: 'layui-btn layui-btn-normal layui-btn-xs',
                            }]
                        ]
                    }
                ]],
            });

            ea.listen();
        },
        detail: function () {

            ea.listen();
        }, express: function () {

            ea.listen();
        }
    };
});
